package command.emocao;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import model.Emocao;

import command.ICommand;
import dao.EmocaoDAO;

public class ListarEmocaoCommand implements ICommand{

	@Override
	public String execute(HttpServletRequest request) throws ServletException,IOException {
		EmocaoDAO dao = new EmocaoDAO();
		String sel = request.getParameter("selecao");
		String erro = request.getParameter("erro");
		
		try {
			ArrayList<Emocao> emocoes = dao.listar();
			request.setAttribute("emocoes", emocoes);
			request.setAttribute("erro", erro);
			if(sel == null){
				request.setAttribute("selecao", false);
			}else{
				boolean selecionado = Boolean.parseBoolean(sel);
				request.setAttribute("selecao", selecionado);
			}
			return "/paginas/questionario/configurar_emocao_questionario.jsp";
		} catch (SQLException e) {
			e.printStackTrace();
			return "#";
		}
		
	}

}
